package  
{
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author D5
	 */
	public class MMRadioButton extends MMButton 
	{
		private var _selectedUrl:String;
		private var _unSelectedUrl:String;
		
		private var _textOffSetX:Number = 3;
		
		private var _selected:Boolean;
		private var _value:String;
		private var _needUpdate:Boolean;
		
		
		public function MMRadioButton(selectedUrl:String="/controls/radio_button_1.png",unSelectedUrl:String="/controls/radio_button_2.png") 
		{
			super();
			_selectedUrl = selectedUrl;
			_unSelectedUrl = unSelectedUrl;
			_needUpdate = true;
			mouseChildren = true;
		}
		
		override public function onInit():void
		{
			super.onInit();
			_Bg.source = _selectedUrl;
			_Bg.onClick = clickhandler;
			
			selected =false;
			
		}
		
		private function clickhandler(e:MouseEvent):void 
		{
			selected = true;
		}
		
		override public function onHide():void
		{
			super.onHide();
		}
		
		override public function onShow():void
		{
			super.onShow();
			update();
		}
		
		override public function updateData():void
		{
			super.updateData();
			if (_needUpdate)
			{
				//_label.x += (_Bg.width + _textOffSetX);
				if (_selected)
					_Bg.source = _selectedUrl;
				else
					_Bg.source = _unSelectedUrl;
			}
			
		}
		
		override protected function updateTextAlign():void
		{
			var layerX:Number;
			if (_textAlign ==TEXTALIGN_LEFT)
			{
				_Bg.x=_label.width +_textOffSetX ;
			}else if (_textAlign == TEXTALIGN_RIGHT)
			{
				_Bg.x=_label.width +_textOffSetX ;
			}else
			{
				_label.x = _Bg.width +_textOffSetX ;
			}
			_label.y = (height - _label.height) / 2;
		}
		
		override protected function initEvent():void
		{
			
		}
		
		public function get selected():Boolean { return _selected; }
		
		public function set selected(value:Boolean):void 
		{
			if (_selected != value)
			{
				_selected = value;
				_needUpdate = true
				update();
			}
		}
		
		override public function set backgroupImage(bitmapData:BitmapData):void
		{
			
		}
		
		public function get value():String { return _value; }
		
		public function set value(value:String):void 
		{
			_value = value;
		}
		
	}

}